package model

import (
	"hass.tree.com/bridge/dbhelper"
	"hass.tree.com/bridge/vo"
)

type Member struct {
	ID    int    `gorm:"column:id;parimary_key" json:"id"`
	Name  string `gorm:"column:name" json:"name"`
	Phone string `gorm:"column:phone" json:"phone"`
	Mail  string `gorm:"column:mail" json:"mail"`
}

func FindAllMember() []Member {
	var members []Member
	dbhelper.Db.Find(&members)
	return members
}

func PageMember(page uint64, size uint64) vo.PageVO {
	var members []Member
	offset := (page - 1) * size
	memberDb := dbhelper.Db.Model(&Member{})
	memberDb.Offset(offset).Limit(size).Find(&members).Order("id ASC")
	var total uint64
	memberDb.Count(&total)
	return vo.PageResult(total, page, size, members)
}
